
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'logic.dart';
import 'state.dart';

class MembershipInterestsPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return _MembershipInterestsPage();
  }
}

class _MembershipInterestsPage extends State<MembershipInterestsPage> {
  final MembershipInterestsLogic logic = Get.put(MembershipInterestsLogic());
  final MembershipInterestsState state = Get.find<MembershipInterestsLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        elevation: 0,
        backgroundColor: Color(0xffEA5504),
        title: Text(
          '会员权益',
          style: TextStyle(
            color: Colors.white,
            fontSize: 17,
          ),
        ),
      ),
      body: GetBuilder<MembershipInterestsLogic>(
        builder: (logic) {
          return Container(
            child: SmartRefresher(
              controller: state.controller1,
              header: CustomHeader(
                builder: (BuildContext context, RefreshStatus mode) {
                  Widget body;
                  if (mode == RefreshStatus.completed) {
                    body = CupertinoActivityIndicator();
                  }
                  return Container(
                    height: 55.0,
                    child: Center(child: body),
                  );
                },
              ),
              enablePullDown: true,
              onRefresh: logic.refreshData,
              child: ListView.builder(
                shrinkWrap: true,
                itemBuilder: (context, index) {
                  return Html(
                    style: {
                      'body':Style(
                        padding: EdgeInsets.all(0),
                        margin: EdgeInsets.all(0),
                      ),
                      'p':Style(
                        padding: EdgeInsets.all(0),
                        margin: EdgeInsets.all(0),
                      ),
                    },
                    data: state.listMap[index]['ec_value'],
                  );
                },
                itemCount: state.listMap.length > 0 ? 1 : 0,
              ),
            ),
          );
        },
      ),

    );
  }
}